package org.longgang.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.longgang.bean.PositionResume;
import org.longgang.service.PositionResumeService;
import org.longgang.tools.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class PositionResumeController {

	@Autowired
	private PositionResumeService service;

//	投递简历
	@RequestMapping("/insertPositionResume")
	public Object insertPositionResume(HttpServletRequest request) {
		Integer positionid = Integer.parseInt(request.getParameter("positionid"));
		Integer status = Integer.parseInt(request.getParameter("status"));// 没有用到status

		Integer userid = (Integer) request.getSession().getAttribute("uid");
		Integer positionResume = service.insertPositionResume(new PositionResume(positionid, userid, status));

		ResponseData responseData = new ResponseData(2, positionResume, "查询成功！");
		return responseData;
	}

//	查询当前用户是否投递简历
	@RequestMapping("/selectPositionResumeS")
	public Object selectPositionResumeS(HttpServletRequest request) {
		Integer positionid = Integer.parseInt(request.getParameter("positionid"));
		Integer status = 0;

		Integer userid = (Integer) request.getSession().getAttribute("uid");// 没有用到status
		PositionResume positionResumeS = service.selectPositionResumeS(new PositionResume(positionid, userid, status));

		ResponseData responseData = new ResponseData(2, positionResumeS, "查询成功！");
		return responseData;
	}

//	查询当前用户投递的职位
	@RequestMapping("/selectPositionResumeByU")
	public Object selectPositionResumeByU(HttpServletRequest request) {
		Integer positionid = Integer.parseInt(request.getParameter("positionid"));// 没有用到positionid
		Integer status = Integer.parseInt(request.getParameter("status"));

		Integer userid = (Integer) request.getSession().getAttribute("uid");
		List<PositionResume> list = service.selectPositionResumeByU(new PositionResume(positionid, userid, status));

		ResponseData responseData = new ResponseData(2, list, "查询成功！");
		return responseData;
	}

//	查询当前用户投递的职位某状态下的数量
	@RequestMapping("/sumPRByU")
	public Object sumPRByU(HttpServletRequest request) {
		Integer positionid = Integer.parseInt(request.getParameter("positionid"));// 没有用到positionid
		Integer status = Integer.parseInt(request.getParameter("status"));

		Integer userid = (Integer) request.getSession().getAttribute("uid");
		Integer i = service.sumPRByU(new PositionResume(positionid, userid, status));

		ResponseData responseData = new ResponseData(2, i, "查询成功！");
		return responseData;
	}

//----------------------------------------------------------------------------------------------------
//	查询某职位某状态下的数量
	@RequestMapping("/sumPRByP")
	public Object sumPRByP(HttpServletRequest request) {
		Integer positionid = Integer.parseInt(request.getParameter("positionid"));
		Integer status = Integer.parseInt(request.getParameter("status"));

		Integer companyid = (Integer) request.getSession().getAttribute("cid");// 无用

		Integer i = service.sumPRByP(new PositionResume(positionid, 0, status));

		ResponseData responseData = new ResponseData(3, i, "查询成功！");
		return responseData;
	}

//	查询某职位某状态的用户id
	@RequestMapping("/selectPositionResumeByP")
	public Object selectPositionResumeByP(HttpServletRequest request) {
		Integer positionid = Integer.parseInt(request.getParameter("positionid"));
		Integer status = Integer.parseInt(request.getParameter("status"));

		Integer companyid = (Integer) request.getSession().getAttribute("cid");// 无用

		List<PositionResume> list = service.selectPositionResumeByP(new PositionResume(positionid, 0, status));

		ResponseData responseData = new ResponseData(3, list, "查询成功！");
		return responseData;
	}

//	查询用户投递的职位时间
	@RequestMapping("/selectPositionResumeByUP")
	public Object selectPositionResumeByUP(HttpServletRequest request) {
		Integer positionid = Integer.parseInt(request.getParameter("positionid"));
		Integer status = 0;// 无用
		Integer userid = Integer.parseInt(request.getParameter("userid"));

		PositionResume positionResumeS = service.selectPositionResumeS(new PositionResume(positionid, userid, status));

		ResponseData responseData = new ResponseData(3, positionResumeS, "查询成功！");
		return responseData;
	}

//	根据某职位和用户id更新状态
	@RequestMapping("/updatePositionResume")
	public Object updatePositionResume(HttpServletRequest request) {
		Integer userid = Integer.parseInt(request.getParameter("uid"));
		Integer status = Integer.parseInt(request.getParameter("status"));

		Integer companyid = (Integer) request.getSession().getAttribute("cid");// 无用

		Integer i = service.updatePositionResume(new PositionResume(0, userid, status));

		ResponseData responseData = new ResponseData(3, i, "查询成功！");
		return responseData;
	}

//	根据某职位和用户id更新状态和反馈信息
	@RequestMapping("/rePositionResume")
	public Object rePositionResume(HttpServletRequest request) {
		Integer userid = Integer.parseInt(request.getParameter("uid"));
		Integer positionid = Integer.parseInt(request.getParameter("positionid"));
		Integer status = Integer.parseInt(request.getParameter("status"));
		String b1 = request.getParameter("b1");

		Integer companyid = (Integer) request.getSession().getAttribute("cid");// 无用

		Integer i = service.rePositionResume(new PositionResume(positionid, userid, status, b1));

		ResponseData responseData = new ResponseData(3, i, "查询成功！");
		return responseData;
	}
}
